/**
 * @ClassDescription:
 * @JdkVersion: 1.8
 * @Author: 李白
 * @Created: 2024/4/12 16:00
 */
public class Test {
    public static void func(Animal animal){
    }
    public static Animal func1(){
        Dog dog = new Dog();
        return dog;
    }

    public static void main2(String[] args) {
        Dog dog = new Dog();
        func(dog);
        Animal animal = func1();
    }
    public static void main(String[] args) {
        Animal animal = new Dog("zhangsan",19);//父类创建对象，子类赋值，为向上转型
        if (animal instanceof Dog){//如果animal对象指向的就是用Dog构造方法赋值的空间的地址，那么可以创建一个Dog类的对象dog，来指向animal对象指向的空间
            Dog dog = (Dog)animal;
            dog.bark();
        }else {
            System.out.println("哈哈");
        }


        //System.out.println(animal);
        //System.out.println(animal.name);
    }
}
class Animal{
    public String name;
    public int age;
    public Animal(){

    }
    public Animal(String name,int age){
        this.name = name;
        this.age = age;
    }

    public Animal eat(){
        System.out.println(this.name+"正在吃饭！");
        return null;
    }
}
class Dog extends Animal{
    public void bark(){
        System.out.println(name+"正在狗叫！");
    }

    @Override
    public Animal eat() {
        System.out.println(this.name+"正在吃狗粮");
        return null;
    }

    @Override
    public String toString() {//1.
        return "Dog{" +
                "name='" + name + '\'' +
                ", age=" + age +
                '}';
    }

    /**
     * 方法的重写。返回类型、方法名一样、参数列表一样
     */
   /* public Dog eat(){
        System.out.println(this.name+"正在吃狗粮");
        return null;
    }*/

    public Dog(){
        super();
    }
    public Dog(String name,int age){
        super(name,age);
    }
}
class Cat extends Animal{
    public void miaomiao(){
        System.out.println(name+"正在喵叫");
    }
    public Cat(){
        super();
    }
    public Cat(String name,int age){
        super(name,age);
    }
}